package com.ruoyi.jpmf.controller.jinchang;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jpmf.domain.common.Mfjixieapp;
import com.ruoyi.jpmf.domain.common.Jxtypeinfo;
import com.ruoyi.jpmf.domain.common.Projectinfo;
import com.ruoyi.jpmf.domain.common.Worktypeinfo;
import com.ruoyi.jpmf.service.DemoService;
import com.ruoyi.jpmf.service.Projectservice;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author ruoyi
 * 测试
 */
@Controller
@RequestMapping("/demo")
public class DemoController extends BaseController {

    @Autowired
    DemoService demoService;


    @Autowired
    Projectservice projectservice;

    private String prefix = "jpmf/demo/demo";


    @GetMapping()
    public String demo() {
        return prefix + "/demo";
    }



    @GetMapping("/add")
    public String add(Model model, HttpServletRequest request) {
        List<Projectinfo> projectinfos = projectservice.findproject(null);
        model.addAttribute("projectinfos",projectinfos);
        List<Jxtypeinfo>jxtypeinfos=demoService.findjxtype(null);
        model.addAttribute("jxtypeinfos",jxtypeinfos);
        List<Worktypeinfo> worktypeinfos=demoService.findworktype(null);
        model.addAttribute("worktypeinfos",worktypeinfos);
        return prefix + "/add";
    }

    @GetMapping("/edit")
    public String edit() {
        return prefix + "/edit";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map) {
        startPage();
        return getDataTable(demoService.findData(map));
    }


    @GetMapping("/List")
    public List<Jxtypeinfo> findjxtype(Jxtypeinfo jxtypeinfo) {
        List<Jxtypeinfo>jxtypeinfos=demoService.findjxtype(jxtypeinfo);
        return jxtypeinfos;
    }

    @GetMapping("/lists")
    public List<Worktypeinfo> findworktype(Worktypeinfo worktypeinfo){
        List<Worktypeinfo> worktypeinfos=demoService.findworktype(worktypeinfo);
        return worktypeinfos;
    }


    /**
     * 查询机械进场列表
     */
    @RequiresPermissions("demo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Mfjixieapp mfjixieapp)
    {
        startPage();
        List<Mfjixieapp> list = demoService.selectMfjixieappList(mfjixieapp);
        return getDataTable(list);
    }


    @RequiresPermissions("demo:add")
    @Log(title = "机械进场", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Mfjixieapp mfjixieapp)
    {
        return toAjax(demoService.insertMfjixieapp(mfjixieapp));
    }
}
